<?php

/**
 * contacts actions.
 *
 * @package    ecrm
 * @subpackage contacts
 * @author     Saul Santiago
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contactsActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  	$this->tableColumns = ContantInformationTable::TableColumns();
  }
  
  public function executeAjaxdata(sfWebRequest $request) {
  	sfConfig::set('sf_web_debug', false);
  	$this->getResponse()->setContentType('application/json');
  	$this->contacts = Doctrine::getTable('ContantInformation');
  	$json = $this->contacts->fetchData($request);
  	return $this->renderText($json);
  }
  
  public function executeInfo(sfWebRequest $request)
  {
  	sfConfig::set('sf_web_debug', false);
  	$this->forward404Unless($contantId = $request->getParameter('id'));  	
		$campaigns = Doctrine_Core::getTable('Campaign')->findBy('contant_information_id', $contantId, Doctrine_Core::HYDRATE_ARRAY);
		$personalInfos = array();
		$companyInfos = array();
		$otherInfos = array();
		foreach($campaigns as $campaign) {
			$personalInfos[] = Doctrine_Core::getTable('PersonalInformation')->findBy('id', $campaign['personal_information_id'],Doctrine_Core::HYDRATE_ARRAY);
			$companyInfos[] = Doctrine_Core::getTable('CompanyInformation')->findBy('id', $campaign['company_information_id'],Doctrine_Core::HYDRATE_ARRAY);
			$otherInfos[] = Doctrine_Core::getTable('OtherInformation')->findBy('campaign_id', $campaign['id'],Doctrine_Core::HYDRATE_ARRAY);
		}
		return $this->renderPartial('infos',array('campaigns'=>$campaigns,'personalInfos'=>$personalInfos,'companyInfos'=>$companyInfos,'otherInfos'=>$otherInfos));
  }
  
  
}
